#include "wap_menu.h"
#include "wa_wm.h"
#include "wa_win.h"
#include "wa_screen.h"
#include "wa_menu.h"
#include "wap.h"


static void wap_menu_create(void);
static void wap_menu_del(void);
static void wap_menu_callback(wa_sign* sign);

wa_screen_obj wap_menu_screen = 
{
	.id = WAP_WIN_MENU_ID,
	.create = wap_menu_create,
	.del = wap_menu_del,
};

wa_obj* wap_menu_win;
wa_obj* wap_menu_menu;

extern wa_font font_song_16_ascii;

uint8_t wap_menu_select;

void wap_menu_init(void)
{
	wap_menu_select = 0;
}

static void wap_menu_create(void)
{
	wap_menu_win = wa_win_create(NULL);
	wa_win_set_pos(wap_menu_win, 0, 0);
	wa_win_set_size(wap_menu_win, WA_LCD_W, WA_LCD_H);
	wa_win_set_edge_show(wap_menu_win, wa_nok);
	wa_win_set_callback(wap_menu_win, wap_menu_callback);
	wap_menu_screen.win = wap_menu_win;
	
	wap_menu_menu = wa_menu_create(NULL);
	wa_win_add_obj(wap_menu_win, wap_menu_menu);
	wa_obj_set_pos(wap_menu_menu, 0, 0);
	wa_obj_set_size(wap_menu_menu, WA_LCD_W, WA_LCD_H);
	
	wa_menu_add_option(wap_menu_menu, "label", "-");
	wa_menu_add_option(wap_menu_menu, "img", "-");
	wa_menu_add_option(wap_menu_menu, "checkbox", "-");
	wa_menu_add_option(wap_menu_menu, "processbar", "-");
	wa_menu_add_option(wap_menu_menu, "roller", "-");
	wa_menu_add_option(wap_menu_menu, "slider", "-");
	wa_menu_add_option(wap_menu_menu, "cursor", "-");
	wa_menu_add_option(wap_menu_menu, "imgbtn", "-");
	wa_menu_add_option(wap_menu_menu, "iconlist", "-");
	wa_menu_add_option(wap_menu_menu, "editline", "-");
	wa_menu_add_option(wap_menu_menu, "messagebox", "-");
	wa_menu_add_option(wap_menu_menu, "animation", "-");
	wa_menu_add_option(wap_menu_menu, "chinese", "-");
	
	wa_menu_set_font(wap_menu_menu, &font_song_16_ascii);
	wa_menu_set_space(wap_menu_menu, 0);
	wa_menu_set_dire_type(wap_menu_menu, WA_MENU_DIRE_TYPE_NORMAL);
	wa_menu_set_dire_offset(wap_menu_menu, 0);
	wa_menu_set_cursor_r(wap_menu_menu, 3);
	wa_menu_set_cursor_limit_min(wap_menu_menu, 0);
	wa_menu_set_cursor_limit_max(wap_menu_menu, WA_LCD_H);
	wa_menu_set_scroll_bar_enable(wap_menu_menu, wa_ok);
	wa_menu_set_scroll_bar_line_width(wap_menu_menu, 1);
	wa_menu_set_scroll_bar_block_width(wap_menu_menu, 3);
	wa_menu_set_fore_color(wap_menu_menu, WA_COLOR_FOREGROUND);
	wa_menu_set_back_color(wap_menu_menu, WA_COLOR_BACKGROUND);
	wa_menu_set_select(wap_menu_menu, wap_menu_select);
	wa_menu_init_select_pos(wap_menu_menu);
	wa_menu_set_switch_time_length(wap_menu_menu, 200);
	wa_menu_set_anim_enable(wap_menu_menu, wa_ok);
}

static void wap_menu_del(void)
{
	wa_obj_del(wap_menu_win);
}

static void _wap_menu_paint(wa_obj* obj)
{
}

static void wap_menu_callback(wa_sign* sign)
{
	int sign_id;
	wa_obj* obj;
	sign_id = sign->sign_id;
	obj = sign->obj_dst;

	switch (sign_id)
	{
		case WA_SIGNAL_PAINT:
		{
			_wap_menu_paint(obj);
			break;
		}
		case WA_SIGNAL_NOTIFY_PARENT:
		{	
			break;
		}
		case WA_SIGNAL_USER_KEY_UP:
		{	
			if (wap_menu_select > 0)
			{
				wa_menu_set_select(wap_menu_menu, wap_menu_select - 1);
				wap_menu_select = wa_menu_get_select(wap_menu_menu);
			}
			break;
		}
		case WA_SIGNAL_USER_KEY_DOWN:
		{	
			wa_menu_set_select(wap_menu_menu, wap_menu_select + 1);
			wap_menu_select = wa_menu_get_select(wap_menu_menu);
			break;
		}
		case WA_SIGNAL_USER_KEY_ENTER:
		{	
			if(wap_menu_select == 0)
			{
				wa_screen_switch(WAP_WIN_LABEL_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 1)
			{
				wa_screen_switch(WAP_WIN_IMG_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 2)
			{
				wa_screen_switch(WAP_WIN_CHECKBOX_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 3)
			{
				wa_screen_switch(WAP_WIN_PROCESSBAR_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 4)
			{
				wa_screen_switch(WAP_WIN_ROLLER_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 5)
			{
				wa_screen_switch(WAP_WIN_SLIDER_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 6)
			{
				wa_screen_switch(WAP_WIN_CURSOR_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 7)
			{
				wa_screen_switch(WAP_WIN_IMGBTN_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 8)
			{
				wa_screen_switch(WAP_WIN_ICONLIST_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 9)
			{
				wa_screen_switch(WAP_WIN_EDITLINE_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 10)
			{
				wa_screen_switch(WAP_WIN_MESSAGEBOX_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 11)
			{
				wa_screen_switch(WAP_WIN_ANIMATION_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			else if(wap_menu_select == 12)
			{
				wa_screen_switch(WAP_WIN_CHINESE_ID, WA_SCREEN_SWITCH_TYPE_RIGHT_TOGETHER, 500, wa_nok, wa_nok);
			}
			break;
		}
		case WA_SIGNAL_USER_KEY_ESC:
		{	
			wa_screen_switch(WAP_WIN_MAIN_ID, WA_SCREEN_SWITCH_TYPE_TOP_MOVE_QUIT, 500, wa_nok, wa_nok);
			break;
		}
		default:
		{
			break;
		}
	}
}
